package com.yuyou.fn.tas.pusher.handler;

import com.alibaba.fastjson.JSONArray;
import com.yuyou.fn.common.database.event.EventHandler;
import com.yuyou.fn.common.database.event.IEventHandler;
import com.yuyou.fn.educational.entity.StudentReg;
import com.yuyou.fn.tas.pusher.service.IDataPushService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;


@EventHandler(tables = "yyfn.student_reg")
@Component
public class StudentRegPusher implements IEventHandler {

    @Resource
    private IDataPushService dataPushService;


    @Override
    public void insert(String tableName, JSONArray rowList) {
        handleStudentReg(rowList);
    }

    @Override
    public void update(String tableName, JSONArray rowList, Set<String> updateColumns) {
        handleStudentReg(rowList);
    }

    @Override
    public void delete(String tableName, JSONArray rowList) {

    }

    private void handleStudentReg(JSONArray rowList) {

        List<StudentReg> studentRegs = rowList.toJavaList(StudentReg.class);
        dataPushService.pushStudentReg(studentRegs);
    }
}
